package com.zhanglifan.service.impl;

import com.zhanglifan.domain.Dept;
import com.zhanglifan.service.DeptService;

import java.io.Serializable;
import java.util.List;

public class DeptServiceImpl extends BaseServiceImpl<Dept> implements DeptService {

    @Override
    public void deleteById(Class<Dept> entityClass, Serializable id) {
        List<Dept> depts = find("from Dept where parent.id = ?", Dept.class, new Object[]{id});
        for (Dept dept : depts){
                deleteById(Dept.class,dept.getId());
        }
        super.deleteById(Dept.class,id);
    }

    @Override
    public void getList(String id, List<Dept> list){
        List<Dept> depts = find("from Dept where parent.id = ?", Dept.class, new Object[]{id});
            for (Dept dept : depts){
                getList(dept.getId(),list);
            }
        list.add(get(Dept.class,id));
    }

}
